package com.cefa.finance.dao;

import com.cefa.finance.model.Vehicle;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@SuppressWarnings("ALL")
@Repository
@Transactional
public interface VehicleRepository extends CrudRepository<Vehicle,Long> {

    @Query(value = "select * from cefa_finance_vehicle where vin=?1", nativeQuery = true)
    Vehicle findbyVin(String vin);

    @Query(value = "select end_date_of_lease from cefa_finance_contract where vehicle_id=?1 order by end_date_of_lease DESC limit 1", nativeQuery = true)
    Date findEndDataOfLease(Long vehicleId);

    @Query(value = "select * from cefa_finance_vehicle where block_status is not TRUE ", nativeQuery = true)
    List<Vehicle> findUnBlockedVehicles();
}
